package org.academic.texteditor.gui.helper;

import java.util.HashMap;
import java.util.Map;

import org.academic.texteditor.gui.component.PageContainer;

public class DocumentManager {

	private static DocumentManager instance;
	private Map<String, PageContainer> documents = new HashMap<String, PageContainer>();
	private String actualPageContainer;
	
	public static synchronized DocumentManager getInstance() {
		if (instance == null) {
			instance = new DocumentManager();
		}
		return instance;
	}
	
	public void setActualPageContainer(String actualPageContainer) {
		this.actualPageContainer = actualPageContainer;
	}

	public void addDocument(PageContainer pageContainer) {
		String name = pageContainer.getName();
		if (name == null) {
			name = "Untitled " + documents.size() + 1;
			pageContainer.setName(name);
		}
		documents.put(name, pageContainer);
	}
	
	public PageContainer getDocument(String name) {
		return documents.get(name);
	}

	public PageContainer getDocument() {
		return documents.get(actualPageContainer);
	}
	
}
